import { get, post } from '@/utils/request'

const prefix = 'shop'

export default {
  /**
   * 布局管理
   */
  layout: (name, data) => {
    return get(`${prefix}/layout/${name}`, data)
  },

  /**
   * 分类树
   */
  categoryTree: data => {
    return get(`${prefix}/category/tree`, data)
  },

  /**
   * 分类设置
   */
  categoryConfig: (id, pid) => {
    return get(`${prefix}/category/update`, {
      id: id,
      pid: pid
    })
  },

  /**
   * 更新子级分类
   */
  updateCategory: (data, id, pid) => {
    return post(`${prefix}/category/update?id=${id}&pid=${pid}`, data)
  },

  /**
   * 店铺详情
   */
  storeView: id => {
    return get(`${prefix}/store/view`, {
      id: id
    })
  },

  /**
   * 店铺经营类目接口
   */
  storeCategory: data => {
    return get(`${prefix}/store/category`, data)
  },

  /**
   * 下载
   */
  download: data => {
    return post(`${prefix}/download/index`, data, {
      responseType: 'blob'
    })
  },

  /**
   * 分类设置
   */
  attachment: data => {
    return get(`${prefix}/attach/index`, data)
  },

  /**
   *
   */
  freightTemplateFormConfig: id => {
    return get(`${prefix}/freight/update`, {
      id: id
    })
  },

  /**
   * 运费模板更新
   */
  updateFreightTemplate: (data, id, postMethod = true) => {
    if (postMethod) {
      return post(`${prefix}/freight/update?id=${id}`, data)
    } else {
      return get(`${prefix}/freight/update?id=${id}`)
    }
  },

  /**
   *
   */
  freightTemplates: data => {
    return get(`${prefix}/freight/list`, data)
  },

  /**
   * 更新品牌
   */
  orderClose: (id, data) => {
    return post(`${prefix}/order/close?id=${id}`, data)
  }
}
